home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / xml / gnome / xslt / docbook / common / db-common.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2009-03-17  |  10.8 KB  |  296 lines

  1. <?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
  2. <!--
  3. This program is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU Lesser General Public License as published by the Free
  5. Software Foundation; either version 2 of the License, or (at your option) any
  6. later version.
  7.  
  8. This program is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  11. details.
  12.  
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with this program; see the file COPYING.LGPL.  If not, write to the
  15. Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  16. 02111-1307, USA.
  17. -->
  18.  
  19. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  20.                 xmlns:str="http://exslt.org/strings"
  21.                 exclude-result-prefixes="str"
  22.                 version="1.0">
  23.  
  24. <!--!!==========================================================================
  25. DocBook Common
  26. :Requires: gettext
  27.  
  28. This stylesheet module provides utility templates for DocBook that are
  29. independant of the target format.
  30. -->
  31.  
  32. <xsl:key name="idkey" match="*" use="@id"/>
  33.  
  34.  
  35. <!--**==========================================================================
  36. db.copyright
  37. Outputs copyright information
  38. $node: The #{copyright} element to format
  39.  
  40. This template outputs copyright information from a #{copyright} elements.
  41. It assembles the #{year} and #{holder} elements into a simple copyright
  42. notice, beginning with the copyright symbol "¬©".
  43. -->
  44. <xsl:template name="db.copyright">
  45.   <xsl:param name="node" select="."/>
  46.   <xsl:text>¬© </xsl:text>
  47.   <xsl:for-each select="$node/year">
  48.     <xsl:if test="position() != 1">
  49.       <xsl:call-template name="l10n.gettext">
  50.         <xsl:with-param name="msgid" select="', '"/>
  51.       </xsl:call-template>
  52.     </xsl:if>
  53.     <xsl:apply-templates select="."/>
  54.   </xsl:for-each>
  55.   <xsl:if test="$node/holder">
  56.     <xsl:text>  </xsl:text>
  57.     <xsl:for-each select="$node/holder">
  58.       <xsl:if test="position() != 1">
  59.         <xsl:call-template name="l10n.gettext">
  60.           <xsl:with-param name="msgid" select="', '"/>
  61.         </xsl:call-template>
  62.       </xsl:if>
  63.       <xsl:apply-templates select="."/>
  64.     </xsl:for-each>
  65.   </xsl:if>
  66. </xsl:template>
  67.  
  68.  
  69. <!--**==========================================================================
  70. db.linenumbering
  71. Numbers each line in a verbatim environment
  72. $node: The verbatim element to create the line numbering for
  73. $number: The starting line number
  74.  
  75. This template outputs a string with line numbers for each line in a verbatim
  76. elements.  Each line number is on its own line, allowing the output string to
  77. be placed to the side of the verbatim output.
  78. -->
  79. <xsl:template name="db.linenumbering">
  80.   <xsl:param name="node" select="."/>
  81.   <xsl:param name="number" select="1"/>
  82.   <xsl:param name="string">
  83.     <xsl:choose>
  84.       <xsl:when test="$node/node()[1]/self::text() and starts-with($node/node()[1], ' ')">
  85.         <xsl:value-of select="substring-after(string($node), ' ')"/>
  86.       </xsl:when>
  87.       <xsl:otherwise>
  88.         <xsl:value-of select="string($node)"/>
  89.       </xsl:otherwise>
  90.     </xsl:choose>
  91.   </xsl:param>
  92.   <xsl:choose>
  93.     <xsl:when test="contains($string, ' ')">
  94.       <xsl:number value="$number"/>
  95.       <xsl:text> </xsl:text>
  96.       <xsl:call-template name="db.linenumbering">
  97.         <xsl:with-param name="node" select="$node"/>
  98.         <xsl:with-param name="number" select="$number + 1"/>
  99.         <xsl:with-param name="string"
  100.                         select="substring-after($string, ' ')"/>
  101.       </xsl:call-template>
  102.     </xsl:when>
  103.     <xsl:when test="string-length($string) != 0">
  104.       <xsl:number value="$number"/>
  105.       <xsl:text> </xsl:text>
  106.     </xsl:when>
  107.   </xsl:choose>
  108. </xsl:template>
  109.  
  110.  
  111. <!--**==========================================================================
  112. db.linenumbering.start
  113. Determines the starting line number for a verbatim element
  114. $node: The verbatim element to determine the starting line number for
  115.  
  116. This template determines the starting line number for a verbatim element using
  117. the #{continuation} attribute.  The template finds the first preceding element
  118. of the same name, counts its lines, and handles any #{startinglinenumber} or
  119. #{continuation} element it finds on that element.
  120. -->
  121. <xsl:template name="db.linenumbering.start">
  122.   <xsl:param name="node" select="."/>
  123.   <xsl:choose>
  124.     <xsl:when test="$node/@startinglinenumber">
  125.       <xsl:value-of select="$node/@startinglinenumber"/>
  126.     </xsl:when>
  127.     <xsl:when test="$node/@continuation">
  128.       <xsl:variable name="prev" select="$node/preceding::*[name(.) = name($node)][1]"/>
  129.       <xsl:choose>
  130.         <xsl:when test="count($prev) = 0">1</xsl:when>
  131.         <xsl:otherwise>
  132.           <xsl:variable name="prevcount">
  133.             <xsl:value-of select="count(str:split(string($prev), ' '))"/>
  134.           </xsl:variable>
  135.           <xsl:variable name="prevstart">
  136.             <xsl:call-template name="db.linenumbering.start">
  137.               <xsl:with-param name="node" select="$prev"/>
  138.             </xsl:call-template>
  139.           </xsl:variable>
  140.           <xsl:value-of select="$prevstart + $prevcount"/>
  141.         </xsl:otherwise>
  142.       </xsl:choose>
  143.     </xsl:when>
  144.     <xsl:otherwise>1</xsl:otherwise>
  145.   </xsl:choose>
  146. </xsl:template>
  147.  
  148.  
  149. <!--**==========================================================================
  150. db.orderedlist.start
  151. Determines the number to use for the first #{listitem} in an #{orderedlist}
  152. $node: The #{orderedlist} element to use
  153.  
  154. This template determines the starting number for an #{orderedlist} element using
  155. the #{continuation} attribute.  Thi template finds the first preceding #{orderedlist}
  156. element and counts its list items.  If that element also uses the #{continuation},
  157. this template calls itself recursively to add that element's starting line number
  158. to its list item count.
  159. -->
  160. <xsl:template name="db.orderedlist.start">
  161.   <xsl:param name="node" select="."/>
  162.   <xsl:choose>
  163.     <xsl:when test="$node/@continutation != 'continues'">1</xsl:when>
  164.     <xsl:otherwise>
  165.       <xsl:variable name="prevlist"
  166.                     select="$node/preceding::orderedlist[1]"/>
  167.       <xsl:choose>
  168.         <xsl:when test="count($prevlist) = 0">1</xsl:when>
  169.         <xsl:otherwise>
  170.           <xsl:variable name="prevlength" select="count($prevlist/listitem)"/>
  171.           <xsl:variable name="prevstart">
  172.             <xsl:call-template name="db.orderedlist.start">
  173.               <xsl:with-param name="node" select="$prevlist"/>
  174.             </xsl:call-template>
  175.           </xsl:variable>
  176.           <xsl:value-of select="$prevstart + $prevlength"/>
  177.         </xsl:otherwise>
  178.       </xsl:choose>
  179.     </xsl:otherwise>
  180.   </xsl:choose>
  181. </xsl:template>
  182.  
  183.  
  184. <!--**==========================================================================
  185. db.personname
  186. Outputs the name of a person
  187. $node: The element containing tags such as #{firstname} and #{surname}
  188. $lang: The language rules to use to construct the name
  189.  
  190. This template outputs the name of a person as modelled by the #{personname}
  191. element.  The #{personname} element allows authors to mark up components of
  192. a person's name, such as the person's first name and surname.  This template
  193. assembles those into a string.
  194. -->
  195. <xsl:template name="db.personname">
  196.   <xsl:param name="node" select="."/>
  197.   <!-- FIXME: call i18n.locale -->
  198.   <xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang"/>
  199.  
  200.   <!-- FIXME: Use xsl:choose for different language rules -->
  201.   <xsl:if test="$node/honorific">
  202.     <xsl:apply-templates select="$node/honorific[1]"/>
  203.   </xsl:if>
  204.   <xsl:choose>
  205.     <xsl:when test="$node/@role = 'family-given'">
  206.       <xsl:if test="$node/surname">
  207.         <xsl:if test="$node/honorific">
  208.           <xsl:text> </xsl:text>
  209.         </xsl:if>
  210.         <xsl:apply-templates select="$node/surname[1]"/>
  211.       </xsl:if>
  212.       <xsl:if test="$node/othername">
  213.         <xsl:if test="$node/honorific or $node/surname">
  214.           <xsl:text> </xsl:text>
  215.         </xsl:if>
  216.         <xsl:apply-templates select="$node/othername[1]"/>
  217.       </xsl:if>
  218.       <xsl:if test="$node/firstname">
  219.         <xsl:if test="$node/honorific or $node/surname or $node/othername">
  220.           <xsl:text> </xsl:text>
  221.         </xsl:if>
  222.         <xsl:apply-templates select="$node/firstname[1]"/>
  223.       </xsl:if>
  224.     </xsl:when>
  225.     <xsl:otherwise>
  226.       <xsl:if test="$node/firstname">
  227.         <xsl:if test="$node/honorific">
  228.           <xsl:text> </xsl:text>
  229.         </xsl:if>
  230.         <xsl:apply-templates select="$node/firstname[1]"/>
  231.       </xsl:if>
  232.       <xsl:if test="$node/othername">
  233.         <xsl:if test="$node/honorific or $node/firstname">
  234.           <xsl:text> </xsl:text>
  235.         </xsl:if>
  236.         <xsl:apply-templates select="$node/othername[1]"/>
  237.       </xsl:if>
  238.       <xsl:if test="$node/surname">
  239.         <xsl:if test="$node/honorific or $node/firstname or $node/othername">
  240.           <xsl:text> </xsl:text>
  241.         </xsl:if>
  242.         <xsl:apply-templates select="$node/surname[1]"/>
  243.       </xsl:if>
  244.     </xsl:otherwise>
  245.   </xsl:choose>
  246.   <xsl:if test="$node/lineage">
  247.     <xsl:text>, </xsl:text>
  248.     <xsl:apply-templates select="$node/lineage[1]"/>
  249.   </xsl:if>
  250. </xsl:template>
  251.  
  252.  
  253. <!--**==========================================================================
  254. db.personname.list
  255. Outputs a list of people's names
  256. $nodes: The elements containing tags such as #{firstname} and #{surname}
  257. $lang: The language rules to use to construct the list of names
  258.  
  259. This template outputs a list of names of people as modelled by the #{personname}
  260. element.  The #{personname} element allows authors to mark up components of a
  261. person's name, such as the person's first name and surname.  This template makes
  262. a list formatted according to the locale set in ${lang} and calls the template
  263. *{db.personname} for each element in ${nodes}.
  264. -->
  265. <xsl:template name="db.personname.list">
  266.   <xsl:param name="nodes"/>
  267.   <!-- FIXME: call i18n.locale -->
  268.   <xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang"/>
  269.   <xsl:for-each select="$nodes">
  270.     <xsl:choose>
  271.       <xsl:when test="position() = 1"/>
  272.       <xsl:when test="last() = 2">
  273.         <xsl:call-template name="l10n.gettext">
  274.           <xsl:with-param name="msgid" select="' and '"/>
  275.         </xsl:call-template>
  276.       </xsl:when>
  277.       <xsl:when test="position() = last()">
  278.         <xsl:call-template name="l10n.gettext">
  279.           <xsl:with-param name="msgid" select="', and '"/>
  280.         </xsl:call-template>
  281.       </xsl:when>
  282.       <xsl:otherwise>
  283.         <xsl:call-template name="l10n.gettext">
  284.           <xsl:with-param name="msgid" select="', '"/>
  285.         </xsl:call-template>
  286.       </xsl:otherwise>
  287.     </xsl:choose>
  288.     <xsl:call-template name="db.personname">
  289.       <xsl:with-param name="node" select="."/>
  290.       <xsl:with-param name="lang" select="$lang"/>
  291.     </xsl:call-template>
  292.   </xsl:for-each>
  293. </xsl:template>
  294.  
  295. </xsl:stylesheet>
  296.